home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / dir / dir_scp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-23  |  6.2 KB  |  206 lines

  1. #line 1 "/fzi/prost/stone/SOS3-2/src/dir/dir.c"
  2. /* --------------------------------------------------------------------------
  3.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  4.  *
  5.  * You can use and distribute this software under the terms of the licence
  6.  * you should have received along with this program.
  7.  * If not or if you want additional information, write to
  8.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  9.  * D-7500 Karlsruhe 1, Germany.
  10.  * --------------------------------------------------------------------------
  11.  */
  12. #include "sys.h"
  13. #include "smg.h"
  14. #include "trc_dir.h"
  15. #include "dir_err.h"
  16. #include "dir_sos.h"
  17.  
  18. // *************************************************************************
  19. void _sos_Object_Directory::local_initialize(sos_Object_Directory dir)
  20. // *************************************************************************
  21. {
  22.    T_PROC ("sos_Object_Directory::local_initialize");
  23.    TT (dir_H, T_ENTER);
  24.  
  25.    dir.set_name (sos_String::copy (dir.get_name(), dir.container()));
  26.  
  27.    TT (dir_H, T_LEAVE);
  28. }
  29.  
  30. // *************************************************************************
  31. void _sos_Object_Directory::local_finalize(sos_Object_Directory dir)
  32. // *************************************************************************
  33. {
  34.    T_PROC ("sos_Object_Directory::local_finalize");
  35.    TT (dir_H, T_ENTER);
  36.  
  37.    dir.get_name().destroy();
  38.    agg_iterate_association (dir, sos_String name, sos_Object elem)
  39.       name.destroy();
  40.    agg_iterate_association_end (dir, name, elem);
  41.  
  42.    TT (dir_H, T_LEAVE);
  43. }
  44.  
  45.  
  46. // *************************************************************************
  47. sos_Object_Directory _sos_Object_Directory::root()
  48. // *************************************************************************
  49. {
  50.    T_PROC ("sos_Object_Directory::root");
  51.    TT (dir_H, T_ENTER);
  52.  
  53.    sos_Bool open = (sos_Bool) ((ROOT_CONTAINER.status() == READABLE) OR
  54.                        (ROOT_CONTAINER.status() == WRITEABLE));
  55.  
  56.    if (NOT open) ROOT_CONTAINER.open (READING, WAITING);
  57.  
  58.    sos_Object_Directory d =
  59.       sos_Object_Directory::make (ROOT_CONTAINER.root_object());
  60.  
  61.    if (NOT open) ROOT_CONTAINER.close ();
  62.  
  63.    TT (dir_H, T_LEAVE);
  64.  
  65.    return d;
  66. }
  67.  
  68. // *************************************************************************
  69. sos_Object _sos_Object_Directory::lookup(sos_String path)
  70. // *************************************************************************
  71. {
  72.    T_PROC ("sos_Object_Directory::lookup");
  73.    TT (dir_H, T_ENTER);
  74.  
  75.    sos_Object result = sos_Object_Directory::root();
  76.    sos_Object_Directory dir;
  77.    smg_String s0 = path;
  78.    sos_Cstring s = s0.make_Cstring (SMG_BORROW);
  79.    sos_Cstring name = new char[strlen(s)];
  80.  
  81.    for (;;)
  82.    {  if (s[0] == '/'  AND  result.isa (sos_Object_Directory_type))
  83.      dir = sos_Object_Directory::make (result);
  84.       else
  85.       {  result = sos_Object_Directory::make (NO_OBJECT);
  86.      break;
  87.       }
  88.       if (*++s == EOS)
  89.      break;
  90.       sscanf (s, "%[^/]", name);
  91.       if (name[0] != EOS)
  92.       {  sos_String str = smg_String (name).make_String (TEMP_CONTAINER);
  93.      result = dir [str];
  94.      str.destroy();
  95.      s += strlen (name);
  96.      if (result == NO_OBJECT  OR  s[0] == EOS)
  97.         break;
  98.       }
  99.    }
  100.    delete name;
  101.  
  102.    TT (dir_H, T_LEAVE);
  103.  
  104.    return result;
  105. }
  106.  
  107. // *************************************************************************
  108. void _sos_Object_Directory::insert(sos_Typed_id &_tpid,sos_Object so, sos_Object o)
  109. // *************************************************************************
  110. {
  111.    T_PROC ("sos_Object_Directory::insert");
  112.    TT (dir_H, T_ENTER);
  113.  
  114.    sos_String s = sos_String::make (so);
  115.    sos_String name;
  116.    if (sos_Object_Directory::make(_tpid,this).is_key (s))
  117.       name = s;
  118.    else
  119.       name = sos_String::copy (s, sos_Object_Directory::make(_tpid,this).container());
  120.    _sos_Object_sos_Object_Mapping::insert (_tpid,name, o);
  121.    TT (dir_H, T_LEAVE);
  122. }
  123.  
  124.  
  125. // *************************************************************************
  126. void _sos_Object_Directory::remove(sos_Typed_id &_tpid,sos_Object so)
  127. // *************************************************************************
  128. {
  129.    T_PROC ("sos_Object_Directory::remove");
  130.    TT (dir_H, T_ENTER);
  131.  
  132.    sos_String s = sos_String::make (so);
  133.    sos_Cursor c = sos_Object_Directory::make(_tpid,this).open_cursor ();
  134.    sos_Object_Directory::make(_tpid,this).move_cursor (c, s);
  135.    sos_Object name = sos_Object_Directory::make(_tpid,this).get_key (c);
  136.    _sos_Object_sos_Object_Mapping::remove (_tpid,s);
  137.    name.destroy();
  138.    sos_Object_Directory::make(_tpid,this).close_cursor (c);
  139.  
  140.    TT (dir_H, T_LEAVE);
  141. }
  142.  
  143. static sos_Object_Directory *wd;
  144.  
  145. // *************************************************************************
  146. void _sos_Object_Directory::set_wd (sos_String path)
  147. // *************************************************************************
  148. {
  149.    T_PROC ("sos_Object_Directory::set_wd");
  150.    TT (dir_H, T_ENTER);
  151.  
  152.    sos_Object d = sos_Object_Directory::lookup (path);
  153.    
  154.    if (d == NO_OBJECT OR NOT d.isa (sos_Object_Directory_type))
  155.    {  sos_Cstring pname = path.make_Cstring();
  156.       err_raise (err_SYS, err_DIR_NO_DIR, pname);
  157.       delete pname;
  158.    }
  159.    else
  160.    {  wd = new sos_Object_Directory;
  161.      *wd = sos_Object_Directory::make (d);
  162.    }
  163.  
  164.    TT (dir_H, T_LEAVE);
  165. }
  166.  
  167. // *************************************************************************
  168. void _sos_Object_Directory::set_wd_from_env ()
  169. // *************************************************************************
  170. {
  171.    T_PROC ("sos_Object_Directory::set_wd_from_env");
  172.    TT (dir_H, T_ENTER);
  173.  
  174.    sos_Cstring e=getenv("SOSDIR");
  175.    if (e==0)
  176.       err_raise (err_SYS, err_DIR_NO_DIR, NULL, FALSE);
  177.    else
  178.    {
  179.       sos_String s = smg_String (e).make_String (TEMP_CONTAINER);
  180.       sos_Object_Directory::set_wd(s);
  181.       s.destroy();
  182.    }
  183.  
  184.    TT (dir_H, T_LEAVE);
  185. }
  186.  
  187. // *************************************************************************
  188. sos_Object_Directory _sos_Object_Directory::get_wd ()
  189. // *************************************************************************
  190. {
  191.    T_PROC ("sos_Object_Directory::get_wd");
  192.    TT (dir_H, T_ENTER);
  193.  
  194.    sos_Object_Directory result;
  195.  
  196.    if (wd)
  197.       result = *wd;
  198.    else
  199.    {  err_raise (err_SYS, err_DIR_NO_WD, NULL, FALSE);;
  200.       result = sos_Object_Directory::make (NO_OBJECT);
  201.    }
  202.  
  203.    TT (dir_H, T_LEAVE);
  204.    return result;
  205. }
  206.